package 多线程.消费者生产者;

import leetcode.Main;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TicketDemo {
    public static void main(String args[]) throws InterruptedException {
        Ticket t = new Ticket();
        Thread t1 = new Thread(t,"售票口1");
        Thread t2 = new Thread(t,"售票口2");
        Thread t3 = new Thread(t,"售票口3");
        t1.start();
        t2.start();
        t3.start();

    }
}

class Ticket implements Runnable{
    private static int count = 100;
    @Override
    public void run() {
        synchronized (Ticket.class){
            try{
                while(true){
                    if(count>0){
                        Thread.sleep(10);
                        System.out.println(Thread.currentThread().getName()+"卖出了第"+count-- + "张票");
                    }else{
                        break;
                    }
                }
            }catch(Exception e){
                e.printStackTrace();
            }
        }

    }
}
